<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="layui/css/layui.css" rel="stylesheet">
    <script src="layui/layui.js"></script>
    <script src="layuimini/js/lay-config.js"></script>
</head>
<body>
<!-- 交易数据的添加div块 -->
    <!--form表单 lay-filter 绑定事件 若有多个form 筛选作用-->
<form id="addUserDemo" lay-filter="addUserDemo" class="layui-form layui-col-space5" style="margin: 50px auto; display: inline-block;text-align: center;">
        <input type="hidden" placeholder="交易ID" name="dealId" id="dealId">
        <input type="hidden" placeholder="证券ID" name="securityId" id="securityId1">
        <input type="hidden" placeholder="证券类型" name="exchangeType" id="exchangeType">
        <!--<input type="hidden" placeholder="账户ID" name="accountId" id="accountId" value="0001">-->

        <input type="hidden" placeholder="结算状态" name="dealState" id="dealState" value="2">
        <div class="layui-inline layui-show-xs-block" style="text-align: center;">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">证券名称</label>
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" placeholder="证券名称" name="securityName" id="securityName">
                <input class="layui-input"  type="hidden" name="securityId" id="securityId">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">账户编号</label>
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" placeholder="账户编号" name="cashId" id="cashId">
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">券商名称</label>
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" placeholder="券商名称" name="brokerName" id="brokerName">
                <input class="layui-input"  type="hidden" name="brokerId" id="brokerId">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">席位名称</label>
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" placeholder="席位名称" name="seatName" id="seatName">
                <input class="layui-input" type="hidden" name="seatId" id="seatId">
<!--                佣金率-->
                <input class="layui-input" type="hidden" name="commission" id="commission">

            </div>
        </div>
        <br>
        <br>
        <div class="grid-demo grid-demo-bg1">
            <div class="layui-form-item" >
                <label class="layui-form-label layui-bg-gray" style="text-align: center">交易方式</label>
                <div class="layui-input-inline">
                    <select name="dealWay" id="dealWay" lay-verify="required">
                        <option value="1">买入</option>
                        <option value="2">卖出</option>
                        <option value="3">分红</option>
                        <option value="4">送股</option>
                    </select>
                </div>
                <div class="layui-inline layui-show-xs-block" style="text-align: right;">
                <label class="layui-form-label layui-bg-gray" style="text-align: center">证券名称</label>
                <div class="layui-inline layui-show-xs-block">
                    <input class="layui-input" placeholder="基金名称" name="fundName" id="fundName">
                    <input class="layui-input"  type="hidden" name="fundId" id="fundId">
                </div>
            </div>
        </div>
        </div>

        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">成交日期</label>
            <div class="layui-inline layui-show-xs-block">
                <input type="date" class="layui-input" placeholder="请输入成交日期" name="dealTime" id="dealTime">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">交易价格</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入交易价格" name="dealPrice" id="dealPrice">
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">结算日期</label>
            <div class="layui-inline layui-show-xs-block">
                <input type="date" class="layui-input" placeholder="请输入结算日期" name="endTime" id="endTime">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">交易数量</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入交易数量" name="dealNumber" ID="dealNumber" onblur="myNum()">
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">结算金额</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入结算金额" name="endMoney" id="endMoney">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block" style="text-align: center">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">交易金额</label>
            <div class="layui-inline layui-show-xs-block">
                <a url="/selectCheng">
                <input class="layui-input" placeholder="请输入交易金额" name="dealMoney" id="dealMoney">
                </a>
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">佣金费用</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入佣金费用" name="commissionFees" id="commissionFees" >
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">过户费</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入过户费" name="transferFee" id="transferFee">
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">印花税</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入印花税" name="stampDuty" id="stampDuty">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">征管费</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入征管费" name="control" id="control">
            </div>
        </div>
        <br>
        <br>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">经手费</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入经手费" name="handle" id="handle">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label layui-bg-gray" style="text-align: center">证券利息</label>
            <div class="layui-inline layui-show-xs-block" style="width: 182px">
                <input class="layui-input" placeholder="请输入证券利息" name="securityInterest" id="securityInterest">
            </div>
        </div>

    <div class="layui-form-item" style="position: absolute;left: 20%; bottom: 20px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addUser"><i class="layui-icon">&#x1005;</i>添加</button>

            <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
        </div>
    </div>
</div>
</form>

<script type="text/javascript" src="layui/lay/modules/tableSelect.js"></script>
<script type="text/javascript">
    layui.use(['form','tableSelect'],function (){
        var form = layui.form;
        var $ = layui.jquery;
        tableSelect = layui.tableSelect;


        form.on('submit(addUser)',function(obj){
            console.log(obj.field);
            $.ajax({
                url:"InsertDealData",
                type:"post",
                data:obj.field,
                dataType:"text",
                contentType:"application/x-www-form-urlencoded",//内容类型  form 表单的
                success:function(msg){
                    if(msg==="ok"){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });



        //新增托管人下拉表格
        tableSelect.render({
            elem: '#securityName',
            checkedKey: 'securityName',
            table: {
                url: 'selectSecurity',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        ,{field: 'securityId', title: 'ID', fixed: 'left'}
                        ,{field: 'securityName', title: '证券名称'}
                        ,{field: 'securityType', title: '证券类型'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.securityName)
                    $("#securityName").val(item.securityName);
                    $("#securityId").val(item.securityId);
                    $("#exchangeType").val(item.securityType);
                });
                elem.val(NEWJSON.join(","))
            }
        });




        tableSelect.render({
            elem: '#cashId',
            checkedKey: 'cashId',
            table: {
                url: '/selectCash',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'bankId', title: '银行卡号', edit: 'text', align:'center'}
                        , {field: 'cashId', title: '现金账号Id', edit: 'text', align:'center'}
                        , {field: 'accountName', title: '账户名称', edit: 'text', align:'center'}
                        , {field: 'bankName', title: '银行名称', edit: 'text', align:'center'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cashId)
                    $("#cashId").val(item.cashId)
                });
                elem.val(NEWJSON.join(","))
            }
        });


        tableSelect.render({
            elem: '#brokerName',
            checkedKey: 'brokerName',
            table: {
                url: 'selectBroker',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'brokerId', title: '券商ID'}
                        , {field: 'brokerName', title: '券商名称'}
                        , {field: 'brokerRemark', title: '券商备注'}
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.brokerName)
                    $("#brokerName").val(item.brokerName)
                    $("#brokerId").val(item.brokerId);
                });
                elem.val(NEWJSON.join(","))
            }
        });


        tableSelect.render({
            elem: '#seatName',
            checkedKey: 'seatName',
            table: {
                url: 'selectDealSeatMap',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        , {field: 'seatId', title: '席位Id'}
                        , {field: 'seatName', title: '席位名称'}
                        , {field: 'seatType', title: '席位类型', templet: function (ExchangeRate) {
                            if (ExchangeRate.seatType == 1) {
                                return '普通席位';
                            } else if (ExchangeRate.seatType == 2) {
                                return 'SVIP席位';
                            }
                        }
                    }
                    ]]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.seatName)
                    $("#seatName").val(item.seatName)
                    $("#seatId").val(item.seatId)
                    $("#commission").val(item.commission);
                });
                elem.val(NEWJSON.join(","))
            }
        });



        tableSelect.render({
            elem: '#fundName',
            checkedKey: 'fundName',
            table: {
                url: 'selectFundSettingMap',
                cols: [
                    [
                        {type: 'radio', fixed: 'left'},
                        {field: 'fundId', title: '基金ID', sort: true, fixed: 'left'}
                        , {field: 'fundName', title: '基金名称'}
                        , {field: 'custodian', title: '基金管理公司'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.fundName)
                    $("#fundName").val(item.fundName)
                    $("#fundId").val(item.fundId)
                });
                elem.val(NEWJSON.join(","))
            }
        });
    });

    function myNum(){
       // alert("交易数据失去焦点事件");
        layui.use(['layer'], function () {
            var $ = layui.$;
            //交易金额 = 数量*价格
            var dealPrice=$("#dealPrice").val();
            var dealNumber1=$("#dealNumber").val();
            //交易金额
            var dealMoney=dealPrice*dealNumber1;
            $("#dealMoney").val(dealMoney);
            //佣金费用 == 交易金额*佣金费率
            var commission = $("#commission").val();
            //alert(commission);
            var commissionFees= Number(commission) * Number(dealMoney)/100;
            $("#commissionFees").val(commissionFees);
            var exchangeType = $("#exchangeType").val();
            //alert(exchangeType);

            $.ajaxSettings.async = false;
            $.post("selectExchangeRateMap2",{exchangeType: exchangeType,}, function(obj2){
                $.each(obj2.data,function(index,exchangeRate){
                    $("#transferFee").val(exchangeRate.transferFee);
                    $("#stampDuty").val(exchangeRate.stampDuty);
                    $("#control").val(exchangeRate.collectionFee);
                    $("#handle").val(exchangeRate.handlingFee);
                    $("#securityInterest").val(0);

                });
            });
            $.ajaxSettings.async = true;
            var transferFee = $("#transferFee").val();
            var stampDuty = $("#stampDuty").val();
            var control = $("#control").val();
            var handle = $("#handle").val();
            var securityInterest = $("#securityInterest").val();
            var addNumber = Number(securityInterest) + Number(handle) + Number(control) + Number(stampDuty) + Number(transferFee) + Number(dealMoney) + Number(commissionFees);
            $("#endMoney").val(addNumber);
        });
    }
</script>
</body>
</html>